<template>
  <div class="user-container">
    <!-- 顶部 -->
    <div class="info-box">
      <van-image class="my-image" round :src="userInfo.photo" />
      <h2 class="name">
        {{ userInfo.name }}
        <br />
        <van-tag color="#fff" text-color="#3296fa" type="primary">{{
          userInfo.birthday
        }}</van-tag>
      </h2>
    </div>
    <div class="my-connection">
      <van-row>
        <van-col span="8">
          <van-icon class="my-icon" color="#77aaff" name="newspaper-o" />
          <span>我的作品</span>
        </van-col>
        <van-col span="8">
          <van-icon class="my-icon" color="#ff0000" name="star-o" /><span
            >我的收藏</span
          >
        </van-col>
        <van-col span="8">
          <van-icon class="my-icon" color="#ffaa00" name="tosend" /><span
            >阅读历史</span
          >
        </van-col>
      </van-row>
    </div>
    <!-- 底部的区域 -->
    <div class="bottom">
      <van-cell-group>
        <van-cell icon="edit" title="编辑资料" is-link to="/edit" />
        <van-cell icon="chat-o" title="小智同学" is-link />
        <van-cell icon="setting-o" title="系统设置" is-link />
        <van-cell icon="warning-o" title="退出登录" is-link @click="logout" />
      </van-cell-group>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
// import { getUserInfo } from '../../api/my'
import { removeToken } from '../../utils/token'
export default {
  name: 'my',
  data () {
    return {
      // userInfo: {}
    }
  },
  methods: {
    logout () {
      this.$dialog
        .confirm({
          title: '标题',
          message: '弹窗内容'
        })
        .then(() => {
          // on confirm
          // this.userInfo = {}
          removeToken()
          this.$store.commit('setUserInfo', {})
          this.$router.push({ path: '/home' })
        })
        .catch(() => {
          // on cancel
          // console.log('catch')
        })
    }
  },
  created () {
    // getUserInfo().then(res => {
    //   console.log(res)
    //   this.userInfo = res.data.data
    // })
  },
  computed: mapState(['userInfo'])
  // {
  //   userInfo () {
  //     return this.$store.state.userInfo
  //   }
  // }
}
</script>

<style lang="less">
.user-container {
  .info-box {
    height: 100px;
    background-color: #3296fa;
    display: flex;
    padding-left: 18px;
    justify-content: flex-start;
    align-items: center;
    .my-image {
      width: 60px;
      height: 60px;
      margin-right: 5px;
    }
    .name {
      color: white;
      font-size: 15px;
      font-weight: normal;
      margin-left: 10px;
    }
  }
  .my-connection {
    text-align: center;
    .van-row {
      padding: 20px 0;
      border-bottom: 1px solid #ccc;
      .van-col {
        text-align: center;
        font-size: 12px;
        .van-icon {
          font-size: 25px;
        }
        span {
          display: block;
        }
      }
    }
  }
}
</style>
